require File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/sourdough/app/models/user_mailer')

class UserMailer < ActionMailer::Base

  cattr_accessor :from_address

  def message(email)
    setup_pronetos_email
    @subject     = "#{email[:from].name} has sent you a message on Pronetos"
    @body        = { :from => email[:from], :to => email[:to], :link => email[:link], :message => email[:message] }
    @recipients  = email[:to].email
  end

  def invite(invite)
    setup_pronetos_email
    @subject     = "#{invite[:from].name} has invited you to Pronetos"
    @body        = { :from => invite[:from], :link => invite[:link], :invite => invite[:invite] }
    @recipients  = invite[:invite].email_address
  end

  def invite_to_discipline(invite)
    setup_pronetos_email
    @subject     = "#{invite[:from].name} has invited you to the #{invite[:discipline].name} discipline on Pronetos"
    @body        = { :message => invite[:message], :from => invite[:from], :link => invite[:link], :discipline => invite[:discipline] }
    @recipients  = invite[:email_address]
  end

  def friend_request(request)
    setup_pronetos_email
    @subject     = "#{request[:from].name} has requested to be your colleague on Pronetos"
    @body        = { :from => request[:from], :to => request[:to], :link => request[:link] }
    @recipients  = request[:to].email
  end

  def new_article_notification(article)
    setup_pronetos_email
    @subject     = "A new article has been posted in one of your disciplines on Pronetos"
    @body        = { :to => article[:to], :discipline => article[:discipline], :article => article[:article], :link => article[:link] }
    @recipients  = article[:to].email
  end

  protected

  def setup_pronetos_email
    @from        = from_address
    @sent_on     = Time.now
    @headers     = {}
  end

end
